package com.example.intelligentattendancesystem.service.impl;

import com.example.intelligentattendancesystem.mapping.LateMapping;
import com.example.intelligentattendancesystem.pojo.Late;
import com.example.intelligentattendancesystem.service.LateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author
 * @version 1.0
 * @className LateServiceImpl
 * @since 1.0
 */
@Service
public class LateServiceImpl implements LateService {

    @Autowired
    LateMapping lateMapping;

    @Override
    public List<Late> getLateService(int userId) {
        List<Late> lates = lateMapping.selectLateByUserId(userId);
        return lates;
    }

    @Override
    public List<Late> getAllLateService() {
        List<Late> lates = lateMapping.selectAllLate();
        return lates;
    }

    @Override
    public boolean addLateService(int userId, String lateTime) {
        Late late = new Late(null, userId, lateTime);
        List<Late> lates = lateMapping.selectLateByUserId(userId);
        //发现有相同的数据就添加失败
        for (int i = 0; i < lates.size(); i++) {
            if(lates.get(i).equals(late)){
                return false;
            }
        }

        int i=0;
        i = lateMapping.insertLate(late);
        if (i>0) {
            return true;
        }
        return false;
    }
}
